﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Design/Design.Master" AutoEventWireup="true" CodeBehind="SmsMessageSend.aspx.cs" Inherits="Slja.WEB.WebUI.SmsMessageSend" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript" src="../inc/JS/jquery.js"></script>
    <script type="text/javascript">

        var timer1, timer2;
        var Couter = 0;
        function ShowSendStatus() {
            var ids = $.trim($("#ctl00_ContentPlaceHolder1_hdfSentMsgIDs").val());
            var lbStatus = $("#ctl00_ContentPlaceHolder1_lbStatus");
            Couter++;
            if (Couter > 300) {
                timer1 = window.clearInterval(timer1); //情况timer1
                lbStatus.html("获取状态失败！")
                return;
            }
           
            if (ids !== "" && ids !== "0") {
                var statusList = Slja.WEB.WebUI.SmsMessageSend.GetMsgSendStatus(ids).value;
                var nSuccess = 0;
                var nError = 0;
                var sErrorNO = "";
                for (var i = 0; i < statusList.length; i++) {
                    //这些ID的数据行，若SendStatus出现2或3，则认为信息已经发送出。
                    if (statusList[i].Status == 1 || statusList[i].Status == 0) {
                        break;
                    } else {
                    debugger;
                        if (timer1) {
                            timer1 = window.clearInterval(timer1); //情况timer1
                        }
                        nSuccess = nSuccess + (statusList[i].Status == 2 ? 1 : 0);
                        nError = nError + (statusList[i].Status == 3 ? 1 : 0);
                        sErrorNO += (statusList[i].Status == 3?(statusList[i].RecvNO + ","):"");
                    }
                } //for
                if (!timer1) {
                    var str = "成功发送" + nSuccess + "条";
                    if (nError > 0) {
                        str += ",失败" + nError + "条(" + sErrorNO.substr(0, sErrorNO.length - 1) + ")。";
                    }
                    lbStatus.html(str); //状态
                } else {
                    lbStatus.html(lbStatus.html()+"."); //状态
                }
            } //if
           
        }
        function RecvNewMsg() {
            var tbx = $("#ctl00_ContentPlaceHolder1_tbxDownMsg");
            var arr = Slja.WEB.WebUI.SmsMessageSend.GetMsgReciving().value;
            var str = "";
            if (arr && arr.length > 0) {
                //tbx.val("");
                for (var i = 0; i < arr.length; i++) {
                    str += arr[i].ID + " ";
                    str += arr[i].SendNO + " ";
                    str += arr[i].MsgContent + " ";
                    str += arr[i].RecvTime + " ";
                    str += "\n";
                }
                tbx.val(str);
            }
        }
        function CheckSendStatus() {
            timer1 = window.setInterval("ShowSendStatus()",3000);
        }
        function SetRecivingMsg() {
            timer2 = window.setInterval("RecvNewMsg()", 5000);
        }
        $(function () {
            SetRecivingMsg();
        })
    </script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <fieldset>
       
       <table>
        <tr>
            <td>
                 <asp:TextBox runat="server" ID="tbxReciver" Width="300" Height="50" Text="13331102290" TextMode="MultiLine"></asp:TextBox>
        <br />
        <asp:TextBox runat="server" ID="tbxContent" Width="300" Height="100"  TextMode="MultiLine"></asp:TextBox>
            </td>
            <td>
              <asp:TextBox runat="server" ID="tbxDownMsg" Width="300" Height="150"  TextMode="MultiLine"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td align="center">  
           <asp:Label runat="server" ID="lbStatus"></asp:Label> 
           <asp:Button runat="server" ID="btnSend" Text="发送" />
           <asp:HiddenField runat="server" ID="hdfSentMsgIDs" />
           </td>
            <td align="center">  <asp:Button runat="server" ID="btnRecive" Text="接收" /></td>
        </tr>
        <tr>
            <td></td>
            <td> <asp:Button runat="server" ID="btnDisconnect" Text="断开" /></td>
        </tr>
       </table>
       <div runat="server" ID="pnlMsgHide" style="display:none;"></div>
    </fieldset>
</asp:Content>
